<?php
/*
 * Created on 25.01.2006
 * 
 * Attention: It has to be ensured, that the SecurityFilter is called (matches) before login and logout action methods.
 * 	Otherwise the authKey env attribute would not be initialized. 
 * 
 * config:
 * loginAction  action to use for authentication
 * loginAuthKey key for storing of authentication in session
 */
 
m2import('phpinchains/Filter.php');
 
class SecurityFilter extends phpinchains_Filter
{
    
    var $config;

    function doFilter (& $env, & $chain)
    {
        $env->setAttribute("authKey", $this->config['loginAuthKey']);
        $ctx = & phpinchains_ApplicationContext::getInstance();
        $ctx->debug("SecurityFilter::doFilter ".$this->config['loginAuthKey']."=".$env->getSession($this->config['loginAuthKey']));
        if ($env->getSession($this->config['loginAuthKey']) != true)
        {
            $env->setAttribute("__actionParam__", $this->config['loginAction']);
        }
        $chain->doFilter($env);
    }
    
    function init (& $config)
    {
        $this->config = & $config;
    }

}
?>